<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="库房">
              <a-select  v-model="queryParam.storehouse"    placeholder='请选择冷库'>
                <a-select-option v-for='d in hoseList' :key='d.id' :value='d.code'>{{ d.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="物资名称">
              <a-input placeholder="请输入物资名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="物资编码">
              <a-input placeholder="请输入物资编码" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="规格">
              <a-input placeholder="请输入规格" v-model="queryParam.specs"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">

            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item label="型号">
                <a-input placeholder="请输入型号" v-model="queryParam.modelname"></a-input>
              </a-form-item>
            </a-col>



          </template>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <a-button type="primary" icon="download" @click="handleExportXls('采后物资台账表')">导出</a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>

    <flowerMaterialBook-modal ref="modalForm" @ok="modalFormOk"></flowerMaterialBook-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import FlowerMaterialBookModal from './modules/FlowerMaterialBookModal'
  import JDate from '@/components/jeecg/JDate.vue'

  export default {
    name: "FlowerMaterialBookList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDate,
      FlowerMaterialBookModal
    },
    data () {
      return {
        description: '采后物资台账表管理页面',
        hoseList: [], //冷库
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:40,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'库房',
            align:"center",
            dataIndex: 'storehouse_dictText'
          },{
            title:'成本中心',
            align:"center",
            dataIndex: 'cost_dictText'
          },{
            title:'物资名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'物资编码',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'规格',
            align:"center",
            dataIndex: 'specs'
          },
          {
            title:'型号',
            align:"center",
            dataIndex: 'modelname'
          },{
            title:'入库单位',
            align:"center",
            dataIndex: 'unit'
          }, {
            title:'计量单位',
            align:"center",
            dataIndex: 'unitMeasure'
          },
          {
            title:'总数量',
            align:"center",
            dataIndex: 'totalNum'
          },
          {
            title:'剩余数量',
            align:"center",
            dataIndex: 'num'
          },
          {
            title:'单价',
            align:"center",
            dataIndex: 'price'
          },{
            title:'总价',
            align:"center",
            dataIndex: 'totalPrice'
          },
          // {
          //   title:'状态',
          //   align:"center",
          //   dataIndex: 'state',
          //   customRender: function(text) {
          //     let stateString = ''
          //     switch (text) {
          //       case 0:
          //         stateString = '已入库'
          //         break
          //       case 1:
          //         stateString = '已出库'
          //         break
          //       case 2:
          //         stateString = '删除'
          //         break
          //       case 3:
          //         stateString = '损耗'
          //         break
          //       default:
          //         stateString = '未知'
          //     }
          //     return stateString
          //   },
          // },

          {
            title:'更新人',
            align:"center",
            dataIndex: 'updateBy'
          },
          {
            title:'更新日期',
            align:"center",
            dataIndex: 'updateTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
        ],
        url: {
          list: "/flowermater/flowerMaterialBook/list",
          delete: "/flowermater/flowerMaterialBook/delete",
          deleteBatch: "/flowermater/flowerMaterialBook/deleteBatch",
          exportXlsUrl: "/flowermater/flowerMaterialBook/exportXls",
          importExcelUrl: "flowermater/flowerMaterialBook/importExcel",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    created() {
      this.hoseList =  JSON.parse( localStorage.getItem("ch_storehouse")?localStorage.getItem("ch_storehouse"):"[]")
    },
    methods: {
      initDictConfig(){
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>